package com.hna.eking.AirGisPlt.Test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class PostJDBC {
	
	private static Connection con = null;
	private Statement stmt;
	private ResultSet res;
	
	public void ConnectPostGres(){
		String DriverName = "org.postgresql.Driver";
		String JDBCUrl = "jdbc:postgresql://10.70.94.96:8081/demo";
		
		try {
			Class.forName(DriverName);
			con = DriverManager.getConnection(JDBCUrl, "postgres", "123");
			stmt = con.createStatement();
			System.out.println("Connect successful!!");
		} catch (ClassNotFoundException | SQLException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
	public ResultSet Runqry(String SqlStr) throws SQLException {

		res = stmt.executeQuery(SqlStr);
		return res;
	}
	void next(){
		try {
			res.next();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void RunCtx(String SqlStr) throws SQLException {

		stmt.execute(SqlStr);

	}
	
	public String GeString(String ColName) throws SQLException {
		return res.getString(ColName);
	}

	public long GeLong(String ColName) throws SQLException {
		return res.getLong(ColName);
	}
	
	public Boolean DisCon() {
		try {
			if (!stmt.isClosed()) {
				stmt.close();
			}
			
			if (res != null && !res.isClosed()) {
				res.close();
			}
			
			if (!con.isClosed()) {
				con.close();
			}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return true;
	}
}
